<?php
require_once APP . '/application/models/Alllist.php';

/**
 * 前台专用控制器
、 * 设置默认的视图目录,设置默认视图扩展名为php
 * @package front
 */
class FrontAction extends Request
{
    
	/**
	 * 系统配置信息
	 * 
	 * @var Array
	 */
    public $cfg;
    
    /**
     * 数据库对象
     *
     * @var Mysql
     */
    public $db;
    
    public $baseUrl;
    
    /**
     * 重载控制器
     * 定义默认的视图路径，文件编码，视图扩展名
     * 并调用权限认证
     */
    public function __construct (Route $route) {
        parent::__construct($route);
        $this->setViewPath(dirname ($route->getControllerPath ()) . '/views')//设置视图路径
             ->setAutoRender (false)//设置是否自动渲染页面
             ->setSuffix ('.php');//设置视图后缀名
        
        $controllerName         = $this->getParam('controller');
        $actionName             = $this->getParam('action');
        
        $this->view->baseUrl    = $this->getBaseUrl ();
        $this->baseUrl = $this->view->baseUrl;
        $this->view->fullUrl    = $this->getHost() . $this->getBaseUrl ();
        $this->view->controllerName = $controllerName;
        
        global $cfg;
        $this->cfg = $cfg;
        $this->view->cfg = $cfg;
        $this->db = Mysql::getInstance();
        
        $this->header();
    }
    
    
    /**
     * 输出错误信息
     */
    public function showmessage ($message='', $type='') {
        $message = array("status" => 0, "message" => $message);
        if($type != "")
        	$message['type'] = $type;
    	
    	echo json_encode($message);
    	exit;
    }
    
    /**
     * 内部跳转
     *
     * @param unknown_type $controller
     * @param unknown_type $action
     * @param unknown_type $param
     */
    protected function redirectAction($controller, $action, $param = '') {
    	$url = $this->url($this->view->baseUrl, $controller, $action, $param);
    	header("location:" . $url);
    	exit;
    }
    
    /**
     * 处理头部数据
     *
     */
    private function header()
    {
    	// 读取友情链接
    	$arr_links = $this->db->fetchAll('select * from `link` order by seq desc,id desc');
    	$this->view->arr_links = $arr_links;
    	
    	// 分类读取
    	$obj_list = new Alllist($this->db);
    	$arr_types = $obj_list->getAllListByType($this->cfg['listtype']['xwzx']);
    	$arr_xshd_types = $obj_list->getAllListByType($this->cfg['listtype']['xshd']);
    	$arr_ltrw_types = $obj_list->getAllListByType($this->cfg['listtype']['ltrw']);
    	$arr_gylt_types = $obj_list->getAllListByType($this->cfg['listtype']['gylt']);
    	$arr_publication_types = $obj_list->getAllListByType($this->cfg['listtype']['publication']);
    	
    	$idxtypes = array();
    	$idxtypes['gylt'] = $arr_gylt_types;
    	$idxtypes['ltrw'] = $arr_ltrw_types;
    	$idxtypes['xwzx'] = $arr_types;
    	$idxtypes['xshd'] = $arr_xshd_types;
    	$idxtypes['publication'] = $arr_publication_types;
    	
    	$url = FileCache::getInstance()->get("meet_reg_url");
    	if (empty($url))
    		$url = "#meetreg";
    	
    	$this->view->meeturl = $url;
    	
    	$this->view->idxtypes = $idxtypes;
    }
}